package www.woniuxy.com.class112.controller;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import www.woniuxy.com.class112.dto.PolicyDto;
import www.woniuxy.com.class112.form.achievement.AchievementFdAllForm;
import www.woniuxy.com.class112.form.breeding.AddBreedingForm;
import www.woniuxy.com.class112.form.breeding.BreedingAllForm;
import www.woniuxy.com.class112.form.breeding.BreedingCompileFORM;
import www.woniuxy.com.class112.param.achievement.AchievementFdAllParam;
import www.woniuxy.com.class112.param.breeding.AddBreedingParam;
import www.woniuxy.com.class112.param.breeding.BreedingCompileParam;
import www.woniuxy.com.class112.param.breeding.BreedingfdAllParam;
import www.woniuxy.com.class112.service.BreedingService;
import www.woniuxy.com.class112.util.JwtUtil;
import www.woniuxy.com.class112.util.Result;

import javax.annotation.Resource;

@RestController
@RequestMapping("/breeding")
@Api(tags = "种植技术相关接口")
public class BreedingController {
    @Resource
    private BreedingService breddingService;
    @PostMapping("breedingfdAll")
    @ApiOperation("查询所有种植技术")
    public Result breedingfdAll(@RequestBody BreedingAllForm form)throws Exception{
        BreedingfdAllParam param = BeanUtil.toBean(form, BreedingfdAllParam.class);
        PageInfo<PolicyDto> policyDtos = breddingService.breedingfdAll(param);
        return Result.success("查询成功",policyDtos);
    }
    @PostMapping("userbreedingfdAll")
    @ApiOperation("用户查询所有种植技术")
    public Result userbreedingfdAll(@RequestBody BreedingAllForm form)throws Exception{
        BreedingfdAllParam param = BeanUtil.toBean(form, BreedingfdAllParam.class);
        PageInfo<PolicyDto> policyDtos = breddingService.userbreedingfdAll(param);
        return Result.success("查询成功",policyDtos);
    }
    @GetMapping("/delistbreeding")
    @ApiOperation("下架种植技术")
    public Result delistbreeding(Long policyId)throws Exception{
        breddingService.delistbreeding(policyId);
        return Result.success("下架成功",null);
    }

    @GetMapping("/enablebreeding")
    @ApiOperation("发布种植技术")
    public Result enablebreeding(Long policyId)throws Exception{
        breddingService.enablebreeding(policyId);
        return Result.success("发布种植技术成功",null);
    }
    @GetMapping("/deletebreeding")
    @ApiOperation("删除种植技术")
    public Result deletebreeding(Long policyId)throws Exception{
        breddingService.deletebreeding(policyId);
        return Result.success("删种植技术成功",null);
    }
    @PostMapping("/addbreeding")
    @ApiOperation("添加种植技术")
    public Result addpolicy(@RequestBody AddBreedingForm form, @RequestHeader String token)throws Exception{
        Long userId = JwtUtil.getUserId(token);
        AddBreedingParam param = BeanUtil.toBean(form, AddBreedingParam.class);
        param.setCreaterId(userId);
        breddingService.addbreeding(param);
        return Result.success("添加种植技术成功",null);
    }
    @PostMapping("/breedingCompile")
    @ApiOperation("修改种植技术")
    public Result compilebreeding(@RequestBody BreedingCompileFORM form)throws Exception{
        BreedingCompileParam param = BeanUtil.toBean(form, BreedingCompileParam.class);
        breddingService.compilebreeding(param);
        return Result.success("修改种植技术成功",null);
    }
    @GetMapping("/tapNUm")
    @ApiOperation("添加带你计量")
    public Result tapNUm(Long id)throws Exception{
        breddingService.tapNUm(id);
        return Result.success("添加点击量成功",null);
    }
}
